<?php
/**
 * Created by PhpStorm.
 * User: win10
 * Date: 2018/3/14
 * Time: 11:16
 */
namespace console\controllers;
use yii\console\Controller;
use Yii;
use yii\db\Query;
use api\models\User;

class FunchainController extends Controller
{
    public function actionSendp2p()
    {
        $p2p = 240000;
        $total = (new Query())->from('user')->select('ad_num')->sum('ad_num');
        $avg =  floor($p2p / $total);

        $users = User::find()->all();
        foreach ($users as $k => $v) {
            $add = $v->ad_num * $avg;
            $v->p2p_num = $v->p2p_num + $add;
            $v->save();
            var_dump($v->getErrors());
        }
        return 0;
    }

}